if (typeof(Edushare) == "undefined") Edushare = { };
if (typeof(Edushare.CourseChooser) == "undefined") Edushare.CourseChooser = { };

Edushare.CourseChooser.$ = function(id){
	return document.getElementById(id); 
};

Edushare.CourseChooser.getNumberMandatoryCourses = function(string){
	var tokens = string.split(";");
	var firstToken = tokens[0].split(":");
	if(firstToken.length == 1 || firstToken[1].length == 0)
		return 0;
	var mandatoryTokens = firstToken[1].split(",");
	return mandatoryTokens.length;
};

Edushare.CourseChooser.getMandatoryCourses = function(string) {
	var tokens = string.split(";");
	var firstToken = tokens[0].split(":");
	if(firstToken.length == 1 || firstToken[1].length == 0)
		return new Array();
	var mandatoryTokens = firstToken[1].split(",");
	return mandatoryTokens;
};

Edushare.CourseChooser.getNumberOptionalSlots = function(string){
	var tokens = string.split(";");
	var numOptTokens = 0;
	for(var i=1;i<tokens.length;i++){
		if(tokens[i].length>0)
			numOptTokens++;
	}
	return numOptTokens;
};


Edushare.CourseChooser.getCourseChoices = function(string, slotNo){
	var tokens = string.split(";");
	var numOptTokens = 0;
	for(var i=1;i<tokens.length;i++){
		if(tokens[i].length>0){
			if(slotNo == numOptTokens){
				var firstToken = tokens[i].split(":");
				if(firstToken.length == 1 || firstToken[1].length == 0)
					return new Array();
				var optTokens = firstToken[1].split(",");
				return optTokens;				
			}
			numOptTokens++;
		}
	}
	return new Array();
};



